import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 38917
 * Date: 2025/5/16
 * Time: 02:25
 */
public class Main {
    public static int i = 0;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            String string = in.nextLine();
            TreeNode root = createTree(string);
            inorderTraversal(root);
            i = 0;
        }
    }
    //前序遍历创建二叉树
    public static TreeNode createTree(String string) {
        char cur = string.charAt(i);
        TreeNode root = null;
        if (cur != '#'){
            root = new TreeNode(cur);
            i++;
            root.left = createTree(string);
            root.right = createTree(string);
        }else {
            i++;
        }
        return root;
    }
    //中序遍历
    public static void inorderTraversal(TreeNode root) {
        if (root == null) {
            return;
        }
        inorderTraversal(root.left);
        System.out.print(root.val + " ");
        inorderTraversal(root.right);
    }
}